<template>
	<view>
		<form>
		<view class="mar">
			<text>基本信息\n\n</text>
			<text>商品名称:{{type}}\n</text>
			<view style="display: flex; flex-direction: row;">
				<text style="width: 25%;">商品类型:</text>
			    <uni-data-select
				  style="width: 75%;"
			      v-model="value"
			      :localdata="range"
			      @change="change"
			    ></uni-data-select>
			  </view>
			<view style="display: flex;flex-direction: row;">
				<text style="width: 25%;">商品卖点:</text>
				<textarea placeholder="请输入" auto-height="true" maxlength="30" style="width: 75%; border: 1rpx solid black;" v-model="commodit.info"></textarea>
			</view>
		</view>
		<view class="mar">
			<text>商品价格\n</text>
			<view style="display: flex; flex-direction: row;">
				<text style="width: 20%;">油站价:</text><input placeholder="请输入" type="number" style="width: 80%;border: 1rpx solid black;" v-model="commodit.price"/>
			</view>
			
		</view>
		<view class="mar" style="display: flex; flex-direction: row;">
			<button  size="mini" style="border: 1rpx solid black; background-color: white; color: black; width: 30%;">国标价</button>
			<input style="width: 70%; font-size: 30rpx; border: 1rpx solid black; margin: 10rpx;" type="number" placeholder="请输入" v-model="commodit.gprice"/>
		</view>
		<view class="mar" style="display: flex; flex-direction: row;">
			<button @click="add">保存</button>
			
			<button >上架发布</button>
			
		</view>
		</form>

	</view>
</template>

<script>
	export default {
		data() {
			return {
				value: 0,
				      range: [
				       
				      ],
				show:true,
				items:[],
				type:'',
				pro:{},
				commodit:{
					name:'',
					info:'',
					price:'',
					gprice:'',
					store:this.$store.state.id,
					status:17
					
				},
				types:0
				
			}
		},
		onLoad: function (option) {
			const item = JSON.parse(decodeURIComponent(option.typecode));
			console.log(item)
			this.types=item
			console.log(this.types)
			if(item==0){
				this.type=''
				this.type='油'
			}else{
				this.type=''
				this.type='天然气'
			}
			const baseUrl="http://localhost:8888"
			uni.request({
				url:baseUrl+'/s/commodit-order/find/'+item,
				method:"GET"
			}).then(res=>{
				this.pro=res.data.data
				console.log(res.data.data)
				
				
			})
			uni.request({
				url:baseUrl+'/s/commodit-order/select/'+this.$store.state.id+'/'+item,
				method:"GET"
			}).then(res=>{
				this.range=res.data.data
				console.log(res.data.data)
				
				
			})
			
		
		},
		
		created() {
			
			
		},
		methods: {
			findtype(){
				
				
				
				this.items=''
			},
			change(e) {
				this.commodit.name=e
			        console.log("e:", e);
			},
			add(){
				const baseUrl="http://localhost:8888"
				uni.request({
					url:baseUrl+'/s/commodit/add',
					method:"Post",
					data:this.commodit
				}).then(res=>{
					this.$store.commit('changecount',res.data.data)
					console.log(res.data)
					uni.switchTab({
						url:'/pages/product/product',
						success: function(e) {
						        var page = getCurrentPages().pop();
						        if (page == undefined || page == null) return;
						        page.curSegment = 0;
						        page.show();
						    }
					})
				})
			}
		},
		
	}
</script>

<style>
	.body{
		background-color: aliceblue;
	},
	.mar{
		margin: 20rpx;
	}
</style>

